package com.zgkxzx.sourceanasys.retrofittest;



import java.io.File;
import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

import okhttp3.Cache;
import okhttp3.CacheControl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * @创建者: zgkxzx
 * @创建时间: 2016-9-29
 * @描述: 网络管理类
 * 				包括基地址设置，请求日志打印，网络缓存设置等等
 */
public class ApiManager {
	private final static String TAG = ApiManager.class.getSimpleName();


	public final static String BASE_URL = "www.xxx.com";


	public static ApiManager apiManager;



	//OkHttpClient 初始化
	private OkHttpClient client = new OkHttpClient.Builder()
		.connectTimeout(30, TimeUnit.SECONDS)
		.readTimeout(30, TimeUnit.SECONDS)
		.build();

	private ApiManager() {
	}

	public static ApiManager getInstance() {
		if (apiManager == null) {
			synchronized (ApiManager.class) {
				if (apiManager == null) {
					apiManager = new ApiManager();
				}
			}
		}
		return apiManager;
	}

	public Retrofit initRetrofit() {
		Retrofit retrofit = new Retrofit.Builder()
			.baseUrl(BASE_URL)
			.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
			.client(client)
			.addConverterFactory(GsonConverterFactory.create())
			.build();
		return retrofit;
	}


}
